home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / b_rspfil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-06  |  11.4 KB  |  317 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*             BinkleyTerm File Request Failure Message Module              */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  27. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  28. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  29. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  30. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /*    The Authors can be reached at the following addresses:                */
  34. /*                                                                          */
  35. /*    Robert C. Hartman                      Vincent E. Perriello           */
  36. /*    Spark Software                         VEP Software                   */
  37. /*    427-3 Amherst Street                   111 Carroll Street             */
  38. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  39. /*    Nashua, NH 03061                                                      */
  40. /*                                                                          */
  41. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  42. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  43. /*                                                                          */
  44. /*    Please feel free to contact us at any time to share your comments     */
  45. /*    about our software and/or licensing policies.                         */
  46. /*                                                                          */
  47. /*--------------------------------------------------------------------------*/
  48. #include <stdio.h>
  49. #include <time.h>
  50. #include <ctype.h>
  51. #include <string.h>
  52. #include <stdlib.h>
  53.  
  54. #ifdef __TURBOC__
  55. #include <mem.h>
  56. #include <alloc.h>
  57. #else
  58. #include <memory.h>
  59. #include <malloc.h>
  60. #endif
  61.  
  62. #define WAZOO_SECTION
  63. #include "com.h"
  64. #include "xfer.h"
  65. #include "zmodem.h"
  66. #include "keybd.h"
  67. #include "sbuf.h"
  68. #include "sched.h"
  69. #include "externs.h"
  70. #include "prototyp.h"
  71.  
  72. void Make_Response(char *, int);         /* Build a response      */
  73.  
  74. void Make_Response (data, failure)
  75. char *data;                             /* input = response, output = filename */
  76. int failure;                            /* failure code from file req module   */
  77. {
  78.     FILE *Template, *Response;
  79.     char *dummy_text;
  80.     char *text;
  81.     char *failure_text[10];
  82.     char resp_filename[13];
  83.     char *p, *q, *s;
  84.     struct tm *tp;
  85.     time_t ltime;
  86.     int i;
  87.  
  88.     Template = Response = NULL;
  89.  
  90.     for (i = 0; i < 9; i++)
  91.        failure_text[i] = NULL;
  92.  
  93.     if (((text = malloc (256)) == NULL)
  94.     || ((dummy_text = malloc (256)) == NULL))
  95.        goto resp_failed;
  96.  
  97.     time (<ime);
  98.     tp = localtime (<ime);
  99.     
  100.     errno = 0;
  101.     Template = fopen (CurrentReqTemplate, read_ascii);
  102.     if (got_error (OPEN_msg, CurrentReqTemplate))
  103.        goto resp_failed;
  104.  
  105.     sprintf (resp_filename, "%04x%04x.RSP", alias[assumed].Net, alias[assumed].Node);
  106.     Response = fopen (resp_filename, write_binary);
  107.     if (got_error (OPEN_msg, resp_filename))
  108.        goto resp_failed;
  109.     
  110.     while (!feof (Template))
  111.        {
  112.  
  113. read_line:
  114.  
  115.        e_input[0] = '\0';
  116.        if (fgets (text, 254, Template) == NULL)
  117.           break;
  118.  
  119.        if (text[0] == '%' && text[1] == ';')
  120.           continue;                     /* Comment at start, no output */
  121.        
  122.        p = text;
  123.        q = e_input;
  124.  
  125.        while (*p)
  126.           {
  127.  
  128.           if (*p == '\n')               /* All done if newline seen    */
  129.              break;
  130.  
  131.           if (*p != '%')                /* Copy until(unless) we see % */
  132.              {
  133.              *q++ = *p++;
  134.              continue;
  135.              }
  136.              
  137.           if (*++p == ';')              /* If followed by ; just skip  */
  138.              break;
  139.  
  140.           if ((i = parse(p, rspverbs)) == -1)/* Check against arg list */
  141.              {
  142.              *q++ = '%';                /* No match, use the % literal */
  143.              continue;
  144.              }
  145.           
  146.           switch (i)
  147.           
  148.              {
  149.              
  150.              case 1:                    /* "text"                      */
  151.  
  152.              if (((i = atoi (p = skip_blanks (&p[4]))) < 1) || (i > 9))
  153.                 goto read_line; 
  154.  
  155.              if (!*(p = skip_to_blank (p)) || !*++p)
  156.                 goto read_line; 
  157.              
  158.              if (failure_text[--i] != NULL)
  159.                 free(failure_text[i]);
  160.  
  161.              failure_text[i] = s = malloc (1 + strlen (p));
  162.              if (s == NULL)
  163.                 goto read_line;
  164.              while ((*p) && (*p != '\n'))
  165.                 *s++ = *p++;
  166.              *s++ = '\0';
  167.  
  168.              goto read_line;
  169.              
  170.              case 2:                    /* "date"                      */
  171.              p += 4;
  172.              sprintf (dummy_text,"%2d-%3s-%02d", tp->tm_mday, mtext[tp->tm_mon], tp->tm_year);
  173. scopy:
  174.              s = dummy_text;
  175. ccopy:
  176.              while (*s)
  177.                *q++ = *s++;
  178.              
  179.              break;
  180.              
  181.              case 3:                    /* "time"                      */
  182.              p += 4;
  183.              sprintf (dummy_text, "%2d:%02d", tp->tm_hour, tp->tm_min);
  184.              goto scopy;
  185.              
  186.              case 4:                    /* "bink"                      */
  187.              p += 4;
  188.              s = ANNOUNCE;
  189.              goto ccopy;
  190.              
  191.              case 5:                    /* "mynode"                    */
  192.              p += 6;
  193.              sprintf (dummy_text, "%i:%i/%i.%i",
  194.                      alias[assumed].Zone, alias[assumed].Net, alias[assumed].Node, alias[assumed].Point);
  195.              goto scopy;
  196.              
  197.              case 6:                    /* "system"                    */
  198.              p += 6;
  199.              s = system_name;
  200.              goto ccopy;
  201.              
  202.              case 7:                    /* "sysop"                     */
  203.              p += 5;
  204.              s = sysop;
  205.              goto ccopy;
  206.              
  207.              case 8:                    /* "yrnode"                    */
  208.              p += 6;
  209.              sprintf (dummy_text, "%i:%i/%i.0", remote_zone, remote_net, remote_node);
  210.              goto scopy;
  211.              
  212.              case 9:                    /* "request"                   */
  213.              p += 7;
  214.              s = data;
  215.              goto ccopy;
  216.              
  217.              case 10:                   /* "status"                    */
  218.              p += 6;
  219.              strcpy (dummy_text, p);
  220.              strcpy (text, failure_text [failure-1]);
  221.              strcat (text, dummy_text);
  222.              p = text;
  223.              break;
  224.  
  225.              case 11:                   /* "abort"                     */
  226.  
  227.              if (*(p = skip_blanks (&p[5])))/* If there's an argument, */
  228.                 {
  229.                 if (failure != atoi (p))/* See if it matches failure   */
  230.                    goto read_line;      /* No, keep going.             */
  231.                 }
  232.  
  233.              fclose (Response);         /* Abort things: Close file,   */
  234.              Response = NULL;           /* Keep track of closed file   */
  235.              unlink (resp_filename);    /* Then delete it              */
  236.              goto resp_failed;          /* And take the failure exit   */
  237.  
  238.              case 12:                   /* "exit"                      */
  239.  
  240.              if (*(p = skip_blanks (&p[4])))/* If there's an argument, */
  241.                 {
  242.                 if (failure != atoi (p))/* See if it matches failure   */
  243.                    goto read_line;      /* No, keep going.             */
  244.                 }
  245.  
  246.              else goto resp_done;       /* A match, close the file     */
  247.  
  248.              case 13:                   /* "line"                      */
  249.  
  250.              if ((!(*(p = skip_blanks (&p[4]))))
  251.              || (failure != atoi (p)))  /* If argument doesn't match,  */
  252.                    goto read_line;      /* throw out line, keep going. */
  253.              if (*(p = skip_to_blank (p))) /* If there's any text,     */
  254.                 {
  255.                 strcpy (text, ++p);     /* Copy rest of line down      */
  256.                 p = text;               /* Move pointer to front       */
  257.                 }
  258.              break;
  259.  
  260.              }          /* End switch                 */
  261.           }             /* End while *p               */
  262.  
  263.        *q++ = '\r';
  264.        *q++ = '\n';
  265.        *q = '\0';
  266.  
  267.        errno = 0;
  268.        i = q - e_input;
  269.        fwrite (e_input, i, 1, Response);
  270.        if (got_error (WRITE_msg, resp_filename))
  271.           goto resp_failed;
  272.  
  273.        }                /* End while !feof (Template) */
  274.  
  275. resp_done:
  276.  
  277.    strcpy (data, resp_filename);
  278.  
  279.    fclose (Template);
  280.    Template = NULL;
  281.  
  282.    errno = 0;
  283.    fclose (Response);
  284.    Response = NULL;
  285.    if (!got_error (CLOSE_msg, resp_filename))
  286.       goto cleanup;
  287.  
  288. resp_failed:
  289.  
  290.    *data = '\0';
  291.  
  292.    if (Response != NULL)
  293.       fclose (Response);
  294.  
  295.    if (Template != NULL)
  296.       fclose (Template);
  297.  
  298. cleanup:
  299.  
  300.    for (i = 0; i < 9; i++)
  301.        {
  302.        if (failure_text[i] != NULL)
  303.           {
  304.           free(failure_text[i]);
  305.           failure_text[i] = NULL;
  306.           }
  307.        }
  308.  
  309.    if (text != NULL)
  310.       free (text);
  311.  
  312.    if (dummy_text != NULL)
  313.       free (dummy_text);
  314.  
  315.    return;
  316. }
  317.